home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra_2 / flmgmtcl.zip / DIR.H < prev    next >
C/C++ Source or Header  |  1995-11-02  |  11KB  |  306 lines

  1. // ==========================================================================
  2. //                             Class Specification : CDirSpec
  3. // ==========================================================================
  4.  
  5. // Header file : dir.h
  6.  
  7. // Source : Periphere NV (R.Mortelmans)
  8. // Creation Date :        2nd November. 1995
  9. // Last Modification : 2nd November. 1995
  10.                           
  11. // //////////////////////////////////////////////////////////////////////////
  12.  
  13. // Properties:
  14. //    NO    Abstract class (does not have any objects)
  15. //    YES    Derived from CObject
  16.  
  17. //    NO    Is a Cwnd.                     
  18. //    NO    Two stage creation (constructor & Create())
  19. //    NO    Has a message map
  20. //    NO Needs a resource (template)
  21.  
  22. //    NO    Persistent objects (saveable on disk)      
  23. //    NO    Uses exceptions
  24.  
  25. // //////////////////////////////////////////////////////////////////////////
  26.  
  27. // Desciption :         
  28. //        This class encapsulates the directory specification on Windows NT
  29. //        supported file systems (FAT, VFAT, NTFS, HPFS)
  30. //        A directory consists of a drive specification, followed a subdirectory
  31.  
  32. // Remark:
  33. //        Directory specifications are always represented in upper case characters
  34. //         An implicit conversion is done when the supplied names are in lower case;
  35. //        All member functions starting with "Do" will physically change something
  36. //         on disk.  Other functions only change the internal data.
  37. //        E.g. The normal destructor only destroys the internal representation,
  38. //         to actually remove a directory use DoRemove()
  39.  
  40. // Prerequisites (necessary conditions):
  41. //        
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. #ifndef __DIR_H__
  45. #define __DIR_H__
  46.  
  47. class CDirSpec : public CObject
  48. {
  49. DECLARE_DYNAMIC(CDirSpec)
  50.  
  51. // Data members -------------------------------------------------------------
  52. public:
  53.     
  54. protected:
  55.     CString     m_sDrive;
  56.     CString        m_sSubdirectory;
  57.  
  58. private:
  59.     
  60. // Member functions ---------------------------------------------------------
  61. public:
  62.     CDirSpec();
  63.     // --- In  :
  64.     // --- Out : 
  65.     // --- Returns :
  66.     // --- Effect : Contructor of object
  67.     //                It will initialize the internal state
  68.  
  69.     CDirSpec(const char* pszDirectory);
  70.     // --- In  : pszDirectory : The new drive and directory of the object
  71.     // --- Out : 
  72.     // --- Returns : 
  73.     // --- Effect : 
  74.     // --- Effect : Contruction of an object together with a SetDirectory()
  75.     //                Notice that whether the directory specification is valid or not
  76.     //                cannot be checked in this way
  77.  
  78.     #ifdef WIN32
  79.     BOOL IsChildDir(LPWIN32_FIND_DATA lpFindFileData) const;
  80.     #endif
  81.     
  82.     CDirSpec(const CDirSpec& dirSrc);
  83.     // --- In :    dirSrc : Directory object which will be copied
  84.     // --- Out : 
  85.     // --- Returns :
  86.     // --- Effect : Copy contruction.
  87.     
  88.     BOOL AppendDirectory(const CDirSpec dirSecond);
  89.     // --- In :    dirSecond : The directory object which will be appendec to the object
  90.     // --- Out : 
  91.     // --- Returns : Whether drive and directory specification have a correct format
  92.     // --- Effect : The drive specification of the second directory specification
  93.     //                must be empty or the same as that of this object.
  94.     //                The subdirectory of the second dir spec may not start with
  95.     //                back slash.
  96.     //                It is interpreted as a subdirectory beneath the subdirectory
  97.     //                of this object
  98.     
  99.     const CDirSpec& operator=(const CDirSpec& dirSrc);
  100.     // --- In :    dirSrc : Directory object which will be assign to 'this' directory object
  101.     // --- Out:
  102.     // --- Returns: 
  103.     // --- Effect : Assignment operator
  104.     
  105.     CString GetDrive() const;
  106.     // --- In  :
  107.     // --- Out : 
  108.     // --- Returns :The drive specification of this object
  109.     //                 It consists of a drive letter and a colon
  110.     //                 or an empty string
  111.     // --- Effect : 
  112.     BOOL SetDrive(const char* pszDrive);
  113.     // --- In  : pszDrive : The new drive letter of the object
  114.     // --- Out : 
  115.     // --- Returns : Whether drive specification has a correct format
  116.     //                 Whether it actually exitst is not checked
  117.     // --- Effect : 
  118.     void ForceSetDrive(const char* pszDrive);
  119.     // --- In  : pszDrive : The new drive letter of the object
  120.     // --- Out : 
  121.     // --- Returns : 
  122.     // --- Effect : This function extracts illegal characters and thus
  123.     //                will always succeeds
  124.     
  125.     CString GetSubdirectory() const;
  126.     // --- In  :
  127.     // --- Out : 
  128.     // --- Returns :The subdirectory specification of this object
  129.     //                 It only ends in a back slash when it is the root directory
  130.     //                 The result may be an empty string
  131.     // --- Effect : 
  132.     BOOL SetSubdirectory(const char* pszSubdirectory);
  133.     // --- In  : pszSubdirectory : The new subdirectory of the object
  134.     // --- Out : 
  135.     // --- Returns : Whether subdirectory specification has a correct format
  136.     //                 Wild characters are not allowed
  137.     //                 Whether it actually exitst is not checked
  138.     // --- Effect : 
  139.     void ForceSetSubdirectory(const char* pszSubdirectory);
  140.     // --- In  : pszSubdirectory : The new subdirectory of the object
  141.     // --- Out : 
  142.     // --- Returns : 
  143.     // --- Effect : This function extracts illegal characters and thus
  144.     //                will always succeeds
  145.     
  146.     CDirSpec GetLastSubdirectory() const;
  147.     // --- In  :
  148.     // --- Out : 
  149.     // --- Returns :The last subdirectory specification of this object
  150.     //                Several subdirectories can be seperated by black slashes,
  151.     //                only the last one is returned
  152.     //                (together with the drive specification)
  153.     //                 It only ends in a back slash when it is the root directory
  154.     // --- Effect : 
  155.     void RemoveLastSubdirectory();
  156.     // --- In  :
  157.     // --- Out : 
  158.     // --- Returns :
  159.     // --- Effect : Removes the last subdirectory specification of this object
  160.     //                Several subdirectories can be seperated by black slashes,
  161.     //                only the last one is removed
  162.     //                 The root directory is never removed
  163.  
  164.     CString GetDirectory() const;
  165.     // --- In  :
  166.     // --- Out : 
  167.     // --- Returns :The drive and directory specification of this object
  168.     //                 It only ends in a back slash when it is the root directory
  169.     //                 The result may be an empty string
  170.     // --- Effect : 
  171.     BOOL SetDirectory(const char* pszDirectory);
  172.     // --- In  : pszDirectory : The new drive and directory of the object
  173.     // --- Out : 
  174.     // --- Returns : Whether drive and directory specification have a correct format
  175.     //                 Whether it actually exitst is not checked
  176.     // --- Effect : 
  177.     void ForceSetDirectory(const char* pszDirectory);
  178.     // --- In  : pszDirectory : The new drive and directory of the object
  179.     // --- Out : 
  180.     // --- Returns : 
  181.     // --- Effect : This function extracts illegal characters and thus
  182.     //                will always succeeds
  183.     
  184.     CString GetFileSystemType();
  185.     // --- In  : 
  186.     // --- Out : 
  187.     // --- Returns : The name identifying the file system of this drive
  188.     //                 When the drive spec is not specified, an empty string
  189.     //                 is returned
  190.     // --- Effect : Determines the file system.  
  191.     //                Possible values are (among others):
  192.     //                FAT :  File Allocation Table
  193.     //                HPFS : High Performance File System
  194.     //                NTFS : New Technology File Sytem
  195.     //                CDFS : Compact Disk File System
  196.     //                Notice that WIN16 can only detect FAT-systems
  197.  
  198.     BOOL MakeTemp();
  199.     // --- In  : 
  200.     // --- Out : 
  201.     // --- Returns : Whether the unique directory could be determined
  202.     // --- Effect : Replaces the directory specification by that of the
  203.     //                temporary directory
  204.     
  205.     BOOL MakeUnique();
  206.     // --- In  : 
  207.     // --- Out : 
  208.     // --- Returns : Whether a unique name could be made
  209.     // --- Effect : Replaces the directory specification by another 
  210.     //                directory specification    that does not yet exist on disk
  211.     //                So this can be used to make unique directory names
  212.     
  213.     BOOL MakeLargestExisting();
  214.     // --- In  : 
  215.     // --- Out : 
  216.     // --- Returns : Whether a unique name could be made
  217.     // --- Effect : Removes subdirectories from the directory specification 
  218.     //                 until a directory specification is found that actually exists on disk
  219.     //                (This will become the current directory)
  220.     //                The drive spec is never changed
  221.     //                The resulting dir spec is an absolute spec
  222.  
  223.     BOOL Exists() const;
  224.     // --- In  : 
  225.     // --- Out : 
  226.     // --- Returns : Whether the directory (not a file!) physically exists on disk
  227.     // --- Effect :
  228.     
  229.     BOOL IsEmpty() const;
  230.     // --- In  : 
  231.     // --- Out : 
  232.     // --- Returns : Whether the directory specification is empty
  233.     // --- Effect :
  234.  
  235.     void Empty();
  236.     // --- In  : 
  237.     // --- Out : 
  238.     // --- Returns :
  239.     // --- Effect : CLears the directory specification
  240.     
  241.     BOOL IsEmptyDir() const;
  242.     // --- In  : 
  243.     // --- Out : 
  244.     // --- Returns : Whether the directory is empty = contains no files or other subdirs
  245.     // --- Effect : 
  246.  
  247.     BOOL DoGetCurrentDir();
  248.     // --- In  :
  249.     // --- Out : 
  250.     // --- Returns :Whether it succeeded or not
  251.     // --- Effect : Copies the current DOS drive and directory to the object
  252.     BOOL DoSetCurrentDir() const;    
  253.     // --- In  :
  254.     // --- Out : 
  255.     // --- Returns : Whether it succeeded or not
  256.     // --- Effect : Makes the direcory specified by this object the current
  257.     //                directory
  258.     
  259.     BOOL DoMakeNew() const;
  260.     // --- In  :
  261.     // --- Out : 
  262.     // --- Returns :Whether it succeeded or not
  263.     // --- Effect : Makes a new subdirectory
  264.     //                Several directories can be created in one call
  265.     BOOL DoRemove(BOOL bRecursively = FALSE, BOOL bAlsoRemoveReadOnly = FALSE) const;    
  266.     // --- In  : bRecursively : Whether all underlying subdirectories
  267.     //                            sould be deleted first
  268.     //             bAlsoRemoveReadOnly : Whether to also remove files that are 
  269.     //                            marked as read only (TRUE) or not (FALSE)
  270.     // --- Out : 
  271.     // --- Returns : Whether it succeeded or not
  272.     // --- Effect : Removes the directory
  273.  
  274.     BOOL operator==(CDirSpec dirSpec) const;
  275.     BOOL operator!=(CDirSpec dirSpec) const;
  276.     BOOL operator<=(CDirSpec dirSpec) const;
  277.     BOOL operator<(CDirSpec dirSpec) const;
  278.     BOOL operator>=(CDirSpec dirSpec) const;
  279.     BOOL operator>(CDirSpec dirSpec) const;
  280.     // --- In  : dirSpec : Second object to which this object will be compared
  281.     // --- Out : 
  282.     // --- Returns : FALSE or TRUE
  283.     // --- Effect : Comparison operators
  284.     
  285. #ifdef _DEBUG
  286.     virtual void Dump(CDumpContext&) const;
  287.     virtual void AssertValid() const;
  288. #endif //_DEBUG
  289.  
  290.     virtual ~CDirSpec();
  291.     // --- In  :
  292.     // --- Out : 
  293.     // --- Returns :
  294.     // --- Effect : Destructor of object
  295.  
  296. protected:      
  297.     CDirSpec FindLowerDirectory() const;
  298.     BOOL RemoveAllFiles(BOOL bAlsoRemoveReadOnly = FALSE) const;
  299.  
  300. private:
  301.  
  302. };
  303.  
  304. #endif
  305. // ==========================================================================
  306.